var t = require("../../utils/api.js"), o = getApp();

Page({
    data: {
        value: "",
        city: "北京市",
        cid: 3223,
        recommend: !1,
        show_no: !1,
        diy_community_name: o.globalData.diy_community_name
    },
    onLoad: function(t) {
        var o = this, e = t.city, a = t.cid;
        o.setData({
            city: e,
            cid: a
        }), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        });
    },
    chooseCommunity: function(e) {
        for (var a = this, n = e.currentTarget.dataset.id, i = a.data.recommend, c = 0; c < i.length; c++) if (i[c].m_id == n) {
            var d = {
                openid: wx.getStorageSync("openid"),
                head_openid: i[c].m_openid
            };
            o.globalData.m_openid = i[c].m_openid, t.selectHead(d).then(function(t) {
                console.log(t), 0 == t.errno ? (wx.setStorage({
                    key: "head_info",
                    data: t.data
                }), wx.reLaunch({
                    url: "../template/index"
                })) : wx.showToast({
                    title: "选择团长失败",
                    icon: "none",
                    duration: 2e3
                });
            });
        }
    },
    change: function(t) {
        this.setData({
            value: t.detail
        });
    },
    onSearch: function(o) {
        var e = this.data.value, a = {
            openid: wx.getStorageSync("openid"),
            name: e
        };
        t.getHead(a).then(function(t) {
            console.log(t);
        });
    },
    city: function(t) {
        var o = t.currentTarget.dataset.id;
        wx.reLaunch({
            url: "../group/citys?city_name=" + this.data.city + "&&cid=" + o
        });
    },
    ckeckWord: function(e) {
        console.log(e);
        var a = this, n = o.globalData.latitude, i = o.globalData.longitude, c = e.detail.value, d = a.data.cid;
        console.log(d);
        var r = {
            lat: n,
            lng: i,
            key: c,
            cid: d
        };
        t.GetVillageInfo(r).then(function(t) {
            console.log(t), 0 == t.errno ? (a.setData({
                recommend: t.data,
                show_no: !0
            }), wx.showLoading({
                title: "查询成功",
                icon: "none",
                duration: 1e3
            })) : (a.setData({
                recommend: !1,
                show_no: !1
            }), wx.showLoading({
                title: "暂无数据",
                icon: "none",
                duration: 1e3
            }));
        });
    }
});